//
//  LFBaseViewModel.h
//  AntMarket
//
//  Created by LF on 2017/3/17.
//  Copyright © 2017年 LF. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LFViewModelProtocol.h"
#import "LFNetworkTool.h"
#import "lfBaseModel.h"

//**************************  网络请求失败的分析 ********************
#define NET_ERROR_ANALYZE(block) \
if (error.code == -1001) {\
    block(@"请求超时");\
} else if (![LFNetworkTool shareInstance].isNetUsable) {\
    block(@"没网");\
} else {\
    block(@"");\
}
//****************************************************************


//**************************  两种回调 *****************************
// 成功
typedef void (^ViewModelSuccessBlock)(id data, NSString *successInfo);
// 失败
typedef void (^ViewModelFailureBlock)(NSString *errorInfo);
//******************************************************************

typedef enum : NSUInteger {
    RefreshTypeUp=0,//下拉刷新
    RefreshTypeDown, // 上拉加载
} RefreshType;
@interface NetModel : LFBaseModel
@property (nonatomic, assign) RefreshType type; /**< 刷新类型 */
@property (nonatomic, assign) NSInteger page; /**< 分页 */
@property (nonatomic, strong) NSDictionary *para; /**< 参数 */
@property (nonatomic, copy) NSString *model_name; /**< 参数 */
@property (nonatomic, copy) NSString *api; /**< 参数 */
@property (nonatomic, strong) LFBaseModel *model; /**< <#description#> */
@end

/**
   基类的ViewModel
 */
@interface LFBaseViewModel : NSObject <LFViewModelProtocol>

@property (nonatomic, strong) RACSubject *loadDatasSubject; /**< 加载数据 */
@property (nonatomic, strong) RACSubject *errorSubject; /**< 发送error的Subject */
@property (nonatomic, strong) RACSubject *refreshUISubject; /**< 刷新数据 */
@property (nonatomic, strong) RACSubject *refreshEndSubject; /**< 刷新结束 */

@property (nonatomic, strong) RACCommand *getList; /**< 加载分页 */
@property (nonatomic, strong) NetModel *net; /**< 网络请求数据模型 */
@property (nonatomic, strong) NSMutableArray *datas; /**< 数据 */
- (void) clarifyResult:(LFNetworkResult *)result withStatus1:(void(^)())success status0:(void(^)())failed;

//*************************绑定属性********************************
- (LFNetworkResult *) lf_setValuesForKeysWithJSON:(id)json;
//****************************************************************
@end
